/**
 * 
 */
package com.whu.waterworks.action;

import java.util.ArrayList;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.model.QualityNonNormol;
import com.whu.waterworks.model.QualityNormol;
import com.whu.waterworks.service.QualityNormolService;

/**
 * @author： Joymin
 * @date：2016-4-2 下午5:09:17
 * 说明: 
 */
public class QualityNormAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private QualityNormolService qualityNormolService;
	private QualityNormol  qualityNorm;
	private String jonsStrOfName;
	private ArrayList<QualityNormol>  rsQqualityNormol;
	private String type;
	private String id;
	
	@SuppressWarnings("finally")
	public String addQualityNormol(){
		System.out.println("type="+type);
		String message="";
		ActionContext ctx = ActionContext.getContext();
		if(null!=qualityNorm.getId()){
			id=qualityNorm.getId().toString();
		}		
		try{
			message=qualityNormolService.addQualityNormol(qualityNorm, type);			
		}catch(Exception e){
			e.printStackTrace();
			message="提交失败，请稍后！";
			return message;
		}finally{
			System.out.println(message);
			if(type.equals("1")){
				ctx.put("message", message);//往request里放入req
				ctx.put("urladdress", "./waterQuality/limitOfNormInfo.jsp");//往request里放入req
			}else{
				if(null==id || id.equals("")){
					ctx.put("message", message);//往request里放入req
					ctx.put("urladdress", "./waterQuality/dataOfNormInfo.jsp");//往request里放入req
				}else{
					ctx.put("message", message);//往request里放入req
					ctx.put("urladdress", "./waterQuality/requireDataOfNormInfo.jsp");//往request里放入req
				}
			}				
			return SUCCESS;  
		}		
	}
	
	public String getQualityNormolById(){
		System.out.println("getQualityNormolById start");
		System.out.println("id="+id);
		try{			
			qualityNorm=qualityNormolService.getQualityNormolById(id);			
  	  		return SUCCESS;
		}catch(Exception e){
			e.printStackTrace();			
			return "exception";
		}finally{
			System.out.println("getQualityNormolById end");
		}
		
	}
	
	public String getDataOfLimitNorm(){
		System.out.println("getDataOfLimitNorm start");
		ActionContext ctx = ActionContext.getContext();
		try{			
			qualityNorm=qualityNormolService.getDataOfLimitNorm();			
  	  		return SUCCESS;
		}catch(Exception e){
			e.printStackTrace();
			ctx.put("message", "");//往request里放入req
			ctx.put("urladdress", "./waterQuality/limitOfNormInfo.jsp");//往request里放入req
			return "exception";
		}finally{
			System.out.println("getDataOfLimitNorm end");
		} 
	}
	
	@SuppressWarnings("finally")
	public String delQualityNormol(){
		System.out.println("delQualityNormol start");
		String message="";
		//type=qualityNorm.getType();
		ActionContext ctx = ActionContext.getContext();
		if(null==type || null==qualityNorm){		
			try{
				qualityNorm=new QualityNormol();
				qualityNorm.setId(Integer.valueOf(id));
				message=qualityNormolService.delQualityNormol(qualityNorm);			
	  	  		return SUCCESS;
			}catch(Exception e){
				e.printStackTrace();			
				return SUCCESS;
			}finally{
				ctx.put("message", message);//往request里放入req
				ctx.put("urladdress", "./waterQuality/requireDataOfNormInfo.jsp");//往request里放入req
				return SUCCESS;
			}
		}
		else{			
			try{				
				message=qualityNormolService.delQualityNormol(qualityNorm);			
	  	  		return SUCCESS;
			}catch(Exception e){
				e.printStackTrace();			
				return SUCCESS;
			}finally{
				ctx.put("message", message);//往request里放入req
				ctx.put("urladdress", "./waterQuality/limitOfNormInfo.jsp");//往request里放入req
				return SUCCESS;
			}
		}		 
	}
	
	
	public QualityNormolService getQualityNormolService() {
		return qualityNormolService;
	}
	public void setQualityNormolService(QualityNormolService qualityNormolService) {
		this.qualityNormolService = qualityNormolService;
	}
	
	public QualityNormol getQualityNorm() {
		return qualityNorm;
	}

	public void setQualityNorm(QualityNormol qualityNorm) {
		this.qualityNorm = qualityNorm;
	}

	public String getJonsStrOfName() {
		return jonsStrOfName;
	}
	public void setJonsStrOfName(String jonsStrOfName) {
		this.jonsStrOfName = jonsStrOfName;
	}
	public ArrayList<QualityNormol> getRsQqualityNormol() {
		return rsQqualityNormol;
	}
	public void setRsQqualityNormol(ArrayList<QualityNormol> rsQqualityNormol) {
		this.rsQqualityNormol = rsQqualityNormol;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}	

}
